package com.cheng.activemq.spring.producer;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

/**
 * Author: cheng
 * Date: 13-12-23
 * Time: 下午6:38
 */
public class SpringProducer {

    public static void main(String[] args) {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext-jms.xml");
        JmsTemplate jmsTemplate = (JmsTemplate)applicationContext.getBean("jmsTemplate");
        Destination destination = (Destination)applicationContext.getBean("destination");
        jmsTemplate.send(destination,new MessageCreator() {
            @Override
            public Message createMessage(Session session) throws JMSException {
                return session.createTextMessage("发送消息：" + " Hello ActiveMQ！");
            }
        });
        System.out.println("发送消息成功！");
    }

}
